<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\BaseinitController;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class EvaluateController extends BaseinitController
{
	public function evaluate(Request $request)
	{
        $c_id=$request->input('id');
        $openid=$request->input('openid');
        $evaluation=$request->input('evaluation');
        $exit=DB::table('evaluate')->where('openid',$openid)->where('c_id',$c_id)->where('time','>',time()-30)->first();
        if($exit){
            $data = [
                'code' => 501,
                'msg'   => '不要频繁提交',
            ];
        }else{
            $insertArr=[
                'openid' => $openid,
                'c_id' =>$c_id,
                'evaluation' =>$evaluation,
                'time' =>time()
            ];
            $ok=DB::table('evaluate')->insert($insertArr);
            if($ok){
                $data = [
                    'code' => 200,
                    'msg'   => '成功',
                ];
            }else{
                $data = [
                    'code' => 500,
                    'msg'   => '失败',
                ];
            }
        }
        return response()->json($data);
	}
}